﻿using System;
using System.Data;
using System.Configuration;
using System.Collections;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using HZ.MBSM.DBUtility;
public partial class Supervise_SuperviseChildAdd : System.Web.UI.Page
{
    protected void Page_Load(object sender, EventArgs e)
    {
        System.Collections.Generic.List<HZ.MBSM.DAL.AccountType> _AccountType = new System.Collections.Generic.List<HZ.MBSM.DAL.AccountType>();
        _AccountType.Add(HZ.MBSM.DAL.AccountType.enumSupervise);
        if (HZ.MBSM.BLL.Login.CheckAssert(_AccountType))
        { }

    }
    protected void BtnSave_Click(object sender, EventArgs e)
    {
        Int64 AccountId_father, AccountId = 0;
        HZ.MBSM.Model.Account _Account = (HZ.MBSM.Model.Account)Session["Account"];
        if (_Account != null)
        {
            AccountId_father = SysFun.ToLong(_Account.AccountId);

            Db db = new Db();
            Grove.ORM.ObjectOperator oo = db.GetObjectOperator();
            HZ.MBSM.Model.Account Account = new HZ.MBSM.Model.Account();


            Account.AccountName = txtAccountName.Text;
            Account.Pwd_Bid = SysFun.PasswordEncrypt(txtPwd_Bid.Text);
            Account.Type = SysFun.ToTrim(rdoType.SelectedValue);
            oo.Insert(Account);
            oo.Dispose();
            System.Data.IDataReader dr;
            dr = db.DataReader("select AccountId from account  where AccountName='" + SysFun.ToTrim(txtAccountName.Text) + "'");
            while (dr.Read())
            {
                AccountId = SysFun.ToInt(dr["AccountId"]);
            }
            dr.Close();
            dr.Dispose();
            oo.Dispose();
            //Grove.ORM.ObjectOperator oo1 = db.GetObjectOperator();
            HZ.MBSM.Model.AgencyChild AgencyChild = new HZ.MBSM.Model.AgencyChild();
            string strSql = "insert into AgencyChild (accountid,usercode,username,telephone,zc,accountId_father)";
            strSql += " values( ";
            strSql += "'" + AccountId + "',";
            strSql += "'" + SysFun.ToTrim(txtUserCode.Text) + "',";
            strSql += "'" + SysFun.ToTrim(txtUserName.Text) + "',";
            strSql += "'" + SysFun.ToTrim(txtTelephone.Text) + "',";
            strSql += "'" + SysFun.ToTrim(txtZC.Text) + "',";
            strSql += "'" + AccountId_father + "')";
            db.Command(strSql);
            //AgencyChild.AccountId = AccountId;
            //AgencyChild.UserCode = SysFun.ToTrim(txtUserCode.Text);
            //AgencyChild.AccountId_father = AccountId_father;
            //AgencyChild.Telephone = SysFun.ToTrim(txtTelephone.Text);
            //AgencyChild.UserName = SysFun.ToTrim(txtUserName.Text);
            //AgencyChild.ZC = SysFun.ToTrim(txtZC.Text);
            //AgencyChild.purview = false;
            //oo1.Insert(AgencyChild);

            //oo1.Dispose();
            db.Close();
            // HZ.MBSM.Model.Account _Account = (HZ.MBSM.Model.Account)Session["Account"];
            HZ.MBSM.BLL.LogManage.RecordLoginDetail(_Account.AccountName, Request.UserHostAddress, "插入", "AgencyChild", strSql, "../Agency/AgencyChildAdd.aspx");

        }
        else
        {
            Response.Write("<script language=JavaScript>alert('您还没有登录，暂时无权添加子用户！！！');</script>");
        }
        Response.Write("<script>window.opener.location.reload();window.close();</script>");
    }
}
